﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    //使用InputSystem输入系统
    private PlayerController controller;
    //刚体
    private Rigidbody2D rb;
    //移动速度
    public float speed;
    //移动方向
    public Vector2 moveDir;
    private void OnEnable()
    {
        if (controller == null)
            controller = new PlayerController();
        controller.Enable();
    }
    private void OnDisable()
    {
        controller.Disable();
    }
    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }
    private void Start()
    {
        
    }
    private void Update()
    {
        //通过键盘输入获取移动方向向量
        moveDir = controller.Player.Move.ReadValue<Vector2>();
    }
    private void FixedUpdate()
    {
        Move();
    }

    /// <summary>
    /// 人物移动
    /// </summary>
    private void Move()
    {
        //rb.MovePosition(rb.position + moveDir * Time.deltaTime * speed);
        rb.velocity = moveDir * Time.deltaTime * speed;
    }
}
